﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlServerCe;
using DevExpress.XtraEditors;

namespace frm_view
{
    public partial class frmView : DevExpress.XtraBars.Ribbon.RibbonForm
    {
        /// <summary>
        /// Khởi tạo các CONTROLLER
        /// </summary>


        public frmView()
        {
            InitializeComponent();
           
            
        }

        SqlCeConnection cn = new SqlCeConnection(@"Data Source = D:\DISK E\TT0801MH\QDSP\frm_view\frm_view\dynamic.sdf");
        /// <summary>
        /// Hiển thị treeview 
        /// </summary>
      /*  void HienThiTree()
        { 
                        string MaMon, MaChuong, MaBai;
                        string TenMon, TenChuong, TenBai;
                        DataTable dt = obj_MonHoc.MonHoc_Select_ALL();
                        for (int i = 0; i < dt.Rows.Count; i++)
                        {
                            MaMon = dt.Rows[i]["MaMon"].ToString();
                            TenMon = dt.Rows[i]["TenMon"].ToString();
                            treeView.Nodes.Add(MaMon, TenMon).Tag = MaMon;
                            
                            DataTable dt1 = obj_Chuong.GetData_SelectSTR("SELECT * FROM tblChuong Where MaMon = '"+MaMon+"'");
                            for (int j = 0; j < dt1.Rows.Count; j++)
                            { 
                                MaChuong = dt1.Rows[j]["MaChuong"].ToString();
                                TenChuong = dt1.Rows[j]["TenChuong"].ToString();
                                treeView.Nodes[MaMon].Nodes.Add(MaChuong, TenChuong).Tag=MaChuong;
            
            
                                DataTable dt2 = obj_Bai.Bai_SelectSQL("SELECT * FROM tblBai Where MaChuong = '"+MaChuong+"'");
                                for (int k = 0; k < dt2.Rows.Count; k++)
                                {
                                    MaBai = dt2.Rows[k]["MaBai"].ToString();
                                    TenBai = dt2.Rows[k]["TenBai"].ToString();
                                    treeView.Nodes[MaMon].Nodes[MaChuong].Nodes.Add(MaBai, TenBai).Tag=MaBai;
                                }
                            }
                        }
        }*/
        private void Form1_Load(object sender, EventArgs e)
        {
            
        }
        
        /// <summary>
        /// Hiển Thị Nội dung, video
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
         public static string linkMedia;
        private void treeView_AfterSelect(object sender, TreeViewEventArgs e)
        {
          /*  btnMedia.Hide();
            string FullPathChuong, FullPathBai,FullPathVideo;
            string MaChuong, MaBai,MaVideo;
            //Hiển Thị nội dung Từ Chương
            DataTable dt = obj_Chuong.GetData_SelectAll();
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                MaChuong = dt.Rows[i]["MaChuong"].ToString();
             
                if (treeView.SelectedNode.Tag.ToString() == MaChuong)
                {
                    // Noi Dung Text.....
                    rtbContent.ClearUndo();
                    FullPathChuong = dt.Rows[i]["NoiDung"].ToString();
                    linkMedia = FullPathVideo = dt.Rows[i]["Video"].ToString();
                    try
                    {
                        if (!string.IsNullOrEmpty(FullPathChuong))
                            rtbContent.LoadDocument(@"NoiDung\" + FullPathChuong);
                        if (!string.IsNullOrEmpty(FullPathVideo))
                            btnMedia.Show();
                    }
                    catch (Exception)
                    {

                        XtraMessageBox.Show("Đường Dẫn hoặc đuôi file không hợp lệ");
                    }
                    //

                }

            }
            //Hiển Thị nội dung Từ Bài
         /*   DataTable dt1 = obj_Bai.Bai_SelectALL();
            for (int j = 0; j < dt1.Rows.Count; j++)
            {
                MaBai = dt1.Rows[j]["MaBai"].ToString();
                if (treeView.SelectedNode.Tag.ToString() == MaBai)
                {
                    rtbContent.ClearUndo();
                    FullPathBai = dt1.Rows[j]["NoiDung"].ToString();
                    try
                    {
                        if (!string.IsNullOrEmpty(FullPathBai))
                            rtbContent.LoadDocument(@"NoiDung\" + FullPathBai);
                    }
                    catch (Exception)
                    {

                        XtraMessageBox.Show("Đuôi file không hợp lệ");
                    }


                }
            }*/





            //DataTable dt = obj_Chuong.GetData_SelectAll();
            //for (int i = 0; i < dt.Rows.Count; i++)
            //{
            //    MaChuong = dt.Rows[i]["MaChuong"].ToString();
            //    if (treeView.SelectedNode.Tag.ToString() == MaChuong)
            //    {
            //        rtbContent.ClearUndo();
            //        FullPathChuong = dt.Rows[i]["NoiDung"].ToString();
            //        rtbContent.LoadDocument("" + FullPathChuong);
            //    }
            //    //Code Doc child Node :(
            //    DataTable dt1 = obj_Bai.Bai_SelectSQL("SELECT TenBai FROM tblBai MaChuong ='" + MaChuong + "'");
            //    for (int j = 0; j < dt1.Rows.Count; j++)
            //    {
            //        MaBai = dt1.Rows[j]["MaBai"].ToString();
            //        if (treeView.SelectedNode.Tag.ToString() == MaBai)
            //        {
            //            rtbContent.ClearUndo();
            //            FullPathBai = dt1.Rows[j]["NoiDung"].ToString();
            //            rtbContent.LoadDocument("" + FullPathBai);
            //        }
            //    }


            //}
            
        }


        /// <summary>
        /// Tham số toàn cục nhầm lấy giá trị từ method tstrHide_Click
        /// </summary>
        bool hideImage;
        /// <summary>
        /// Click ẩn hiện chuột
        /// </summary>
        /// <param name="sender">stripImges_Click</param>
        /// <param name="e"></param>
        private void stripImges_Click(object sender, EventArgs e)
        {
            if (hideImage == false)
            {

                pelBanner.Hide();
                pelFooter.Hide();
                hideImage = true;
    
            }

            else
            {
                hideImage = false;
                pelBanner.Show();
                pelFooter.Show();
             
            }
        }

        private void treeView_MouseHover(object sender, EventArgs e)
        {
            splitContainer.SplitterDistance = 200;
        }
        /// <summary>
        /// Ẩn hiện Cây thư mục
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void strTreeview_Click(object sender, EventArgs e)
        {

            splitContainer.SplitterDistance = 0;


        }

        private void tsbAdmin_Click(object sender, EventArgs e)
        {
            frmAdmin frm = new frmAdmin();
            frm.Show();
        }

        private void btnMedia_Click(object sender, EventArgs e)
        {
           // frmMedia media = new frmMedia();
           // media.Show();
            
        }
    }
}
